﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'Id', width: "5%", sortable: false, hide: true, align: 'left', iskey: true },
                    { display: '会员姓名', name: 'MemberName', width: "10%", sortable: false, align: 'left' },
                    { display: '电话', name: 'MemberPhone', width: "10%", sortable: false, align: 'left' },
                    { display: '充值金额', name: 'InCome', width: "10%", sortable: false, align: 'left', process: formatAmt },
                    { display: '充值方式', name: 'BankName', width: "10%", sortable: false, align: 'left' },
                    { display: '充值时间', name: 'CreateTime', width: "10%", sortable: false, align: 'left' },
                    { display: '充值状态', name: 'StatusName', width: "10%", sortable: false, align: 'left' }
                    //{ display: '操作', name: 'Id', width: "10%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);

        function formatNum(v) {
            if (isNaN(v)) {
                return v;
            }
            v = (Math.round((v - 0) * 100)) / 100;
            v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v
                    + "0" : v);
            v = String(v);
            var ps = v.split('.');
            var whole = ps[0];
            var sub = ps[1] ? '.' + ps[1] : '.00';
            var r = /(\d+)(\d{3})/;
            while (r.test(whole)) {
                whole = whole.replace(r, '$1' + ',' + '$2');
            }
            v = whole + sub;

            return v;
        }


        function formatAmt(value, cell) {
            return "<span style='text-decoration:none;' class='abtn' >" + formatNum(value) + "</span>";

        }

        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='审核' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>审核</a>");
            return ops.join("");
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            location.href = url;
        });

        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };
        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          layer.msg('操作成功！', 2, 9);;
                          xjgrid.Reload();
                      }
                      else {
                          layer.msg('操作失败！' + res.Message, 2, 8);
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);